﻿using AnesSystem.Models;
using AnesSystem.Services;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    class ConfigLiquidTypesCtrlViewModel: BaseViewModel<ConfigLiquidTypesCtrlViewModel>
    {
        #region Variables

        private string _seachValue = "";

        private ObservableCollection<ConfigLiquidTypesModel> _disConfigLiquidTypesModel = new ObservableCollection<ConfigLiquidTypesModel>();
        #endregion

        #region Constructor

        public ConfigLiquidTypesCtrlViewModel()
        {
        }

        #endregion

        #region Properties
        public string SeachValue
        {
            get
            {
                return _seachValue;
            }
            set
            {
                _seachValue = value;
                RaisePropertyChanged("DisConfigLiquidTypesModel");

            }
        }
        public ObservableCollection<ConfigLiquidTypesModel> DisConfigLiquidTypesModel
        {
            get
            {
                _disConfigLiquidTypesModel.Clear();
                List<ConfigLiquidTypesModel> lst = DataManager.Instance.ConfigLiquidTypesModelList.ToList().Where(O => O.Name.Contains(_seachValue)).ToList();
                foreach (var item in lst)
                {
                    item.PropertyChanged += Item_PropertyChanged;
                    _disConfigLiquidTypesModel.Add(item);
                }
                return _disConfigLiquidTypesModel;
            }

            set
            {
                _disConfigLiquidTypesModel = value;
                RaisePropertyChanged("DisConfigLiquidTypesModel");
            }
        }

        #endregion

        #region Event

        #endregion

        #region Private Methods
        private void AddConfigLiquidTypesModel(ConfigLiquidTypesModel obj)
        {
            if (obj.Id != new ObjectId("000000000000000000000000"))
            {

                ConfigLiquidTypesModelService.Instance.Update(obj);
                ConfigLiquidTypesDataGridViewModel.Instance.ConfigLiquidTypesModel.Add(obj);
            }
            else ConfigLiquidTypesModelService.Instance.Insert(obj);


        }
        private void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            ConfigLiquidTypesModelService.Instance.Update(sender as ConfigLiquidTypesModel);
        }

        #endregion

        #region Public/Protected Methods
        public void DelConfigLiquidTypesModel(ConfigLiquidTypesModel configLiquidTypesModel)
        {
            if (configLiquidTypesModel != null)
            {
                ConfigLiquidTypesDataGridViewModel.Instance.ConfigLiquidTypesModel.Remove(configLiquidTypesModel);
                RaisePropertyChanged("DisConfigLiquidTypesModel");
                ConfigEventModelService.Instance.DeleteById(configLiquidTypesModel.Id);
            }
        }

        public void AddRow()
        {
            ConfigLiquidTypesModel model = new ConfigLiquidTypesModel();
            DisConfigLiquidTypesModel.Insert(0, model);
            model.PropertyChanged += Model_PropertyChanged;
        }
        #endregion

        #region EventHandlers
        private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            AddConfigLiquidTypesModel(sender as ConfigLiquidTypesModel);
        }
        #endregion

        #region Command

        #region ChangeDoctorCommand

        #endregion

        #region OpenPopupCommand

        #endregion
        #endregion

    }
}
